<template>
  <uni-popup ref="popup" type="center" :is-mask-click="isMaskClick" @maskClick="handleMaskClick">
    <view class="popup">
      <image v-if="data.status == '4'" class="popup-logo" src="/static/images/online-examination/icon-zt.png" />
      <image v-else class="popup-logo" :src="logoSrc" />
      <view class="popup-content">
        <view
          :class="[
            'popup-content-hd',
            { 'popup-content-hd-f': status === examinationStatus.FAIL },
            { 'popup-content-hd-s': status === examinationStatus.SUCCESS }
          ]"
          >{{ data.status == '4' ? '请等待阅卷' : title }}</view
        >
        <slot>
          <view
            class="popup-content-slot"
            v-if="status === examinationStatus.FAIL || status === examinationStatus.SUCCESS"
          >
            <view class="popup-content-f">
              您的得分为：
              <text
                :class="[
                  { 'popup-content-hd-f': status === examinationStatus.FAIL },
                  { 'popup-content-hd-s': status === examinationStatus.SUCCESS }
                ]"
                >{{ data.status == '4' ? '--' : data.score }}</text
              >
              分
            </view>
            <view class="popup-content-row">
              <view>
                <view>{{ data.status == '4' ? '--' : data.errors }}</view>
                <view>错题数</view>
              </view>
              <view>
                <view>{{ data.qualifying }}</view>
                <view>合格分数线</view>
              </view>
            </view>
          </view>
        </slot>
      </view>
      <view class="popup-footer">
        <view v-if="isPause" class="popup-footer-1" @click="handleConfirm">现在交卷</view>
        <view v-if="isPause" class="popup-footer-2" @click="handleCancel">继续考试</view>
        <view v-if="!isPause" class="popup-footer-3" @click="handleEnded">我知道了</view>
      </view>
    </view>
  </uni-popup>
</template>
<script>
import { examinationStatus } from '@/utils/constant'
export default {
  props: {
    // 点击蒙层是否关闭
    isMaskClick: {
      type: Boolean,
      default: false
    },
    modelValue: {
      type: Boolean,
      default: false
    },
    status: {
      type: Number,
      default: examinationStatus.PAUSE
    },
    /**
     * {
     *  score:得分,
     *  errors:错题
     *  no_answer：未答
     *  qualifying: 合格分数线
     * }
     */
    data: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      examinationStatus
    }
  },
  model: {
    prop: 'modelValue',
    event: 'update:modelValue'
  },
  created() {},
  emits: ['cancel', 'confirm', 'update:modelValue'],
  watch: {
    modelValue(newValue, oldValue) {
      if (newValue === oldValue) return
      if (newValue) return this.open()
      this.close()
    }
  },
  computed: {
    isPause() {
      return this.status === examinationStatus.PAUSE
    },
    title() {
      switch (this.status) {
        case examinationStatus.PAUSE:
          return '考试暂停中'
        case examinationStatus.FAIL:
          return '成绩不合格'
        case examinationStatus.SUCCESS:
          return '成绩合格'
        default:
          return '考试暂停中'
      }
    },
    logoSrc() {
      let suffix
      switch (this.status) {
        case examinationStatus.PAUSE:
          suffix = 'zt'
          break
        case examinationStatus.FAIL:
          suffix = 'sb'
          break
        case examinationStatus.SUCCESS:
          suffix = 'tg'
          break
        default:
          suffix = 'zt'
      }
      return `/static/images/online-examination/icon-${suffix}.png`
    }
  },
  methods: {
    open() {
      this.$refs.popup.open('center')
    },
    close() {
      this.$refs.popup.close()
    },
    //取消
    handleCancel() {
      this.$emit('cancel')
      this.$emit('update:modelValue', false)
      this.close()
    },
    // 确认
    handleConfirm() {
      this.$emit('confirm')
      this.$emit('update:modelValue', false)
      this.close()
    },
    // 结束
    handleEnded() {
      this.$emit('ended')
      this.$emit('update:modelValue', false)
      this.close()
    },
    handleMaskClick() {
      this.handleCancel()
    }
  }
}
</script>
<style scoped lang="scss">
.popup {
  font-family: PingFang SC-Regular, PingFang SC;
  background: #fff;
  width: 650rpx;
  height: 695rpx;
  position: relative;
  background: #ffffff;
  border-radius: 20rpx 20rpx 20rpx 20rpx;
  opacity: 1;
  padding: 60rpx 50rpx 40rpx 50rpx;
}
.popup-logo {
  width: 247rpx;
  height: 198rpx;
  margin: 0 auto;
  display: block;
}
.popup-content {
  height: 270rpx;
}
.popup-content-hd {
  font-weight: bold;
  color: #333333;
  font-size: 40rpx;
  font-family: PingFang SC-Bold, PingFang SC;
  text-align: center;
  padding-top: 33rpx;
  margin-bottom: 30rpx;
}
.popup-footer {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 34rpx;
  padding: 0 50rpx;
  color: #454a5e;
  box-sizing: border-box;
  position: absolute;
  z-index: 1;
  left: 0;
  bottom: 40rpx;
  .popup-footer-1,
  .popup-footer-2 {
    width: 246rpx;
    height: 88rpx;
    text-align: center;
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    line-height: 88rpx;
    background: #c4c088;
    color: #fff;
  }
  .popup-footer-2 {
    background: #454a5e;
  }
  .popup-footer-3 {
    background: #ececec;
    border-radius: 44rpx 44rpx 44rpx 44rpx;
    width: 500rpx;
    color: #666666;
    line-height: 88rpx;
    text-align: center;
    height: 88rpx;
    margin: 0 auto;
    font-size: 34rpx;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
  }
}

.popup-content-f {
  font-size: 30rpx;
  color: #666666;
  padding-top: 10rpx;
  text-align: center;
  margin-bottom: 38rpx;
  text {
    font-weight: bold;
  }
}
.popup-content-row {
  display: flex;
  align-items: center;
  color: #666666;
  font-size: 26rpx;
  font-weight: 400;
  justify-content: space-between;
}
.popup-content-row > view {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.popup-content-row > view view:first-child {
  font-weight: bold;
  color: #333333;
  line-height: 54rpx;
  font-size: 36rpx;
}
.popup-content-hd-f {
  color: #a14430;
}
.popup-content-hd-s {
  color: #88b4c4;
}
</style>
